package ca.swank.hardquor;

// import java.util.Comparable;

public class WallMove extends Move implements Comparable
{ private int[] a1, a2, b1, b2;

  public WallMove(int[] a1, int[] a2, int[] b1, int[] b2)
  { this.a1 = a1;
    this.a2 = a2;
    this.b1 = b1;
    this.b2 = b2;
  }

  public int[] getA1() { return a1; }
  public int[] getA2() { return a2; }
  public int[] getB1() { return b1; }
  public int[] getB2() { return b2; }
  public int[] a1() { return getA1(); }
  public int[] a2() { return getA2(); }
  public int[] b1() { return getB1(); }
  public int[] b2() { return getB2(); }

  public String toString()
  { return "WALL[" + coordToString(a1) + " " + coordToString(a2)
             + " " + coordToString(b1) + " " + coordToString(b2) + "]";
  }
  
  public int[] getBottomLeft()
  { return hardquorSimpleBoard.getBottomLeft(a1, a2, b1, b2);
  }

  public boolean isHorizontal()
  { return (a1[0] == b1[0]);
  }
  
  public WallMove[] getMutexWalls()
  { if(isHorizontal())
    { return new WallMove[] { new WallMove(a1, b1, a2, b2), // criss cross member
                              new WallMove(new int[] { a1[0] - 1, a1[1] }, new int[] { a2[0] - 1, a2[1] }, 
                                           new int[] { b1[0] - 1, b1[1] }, new int[] { b2[0] - 1, b2[1] }),
                              new WallMove(new int[] { a1[0] + 1, a1[1] }, new int[] { a2[0] + 1, a2[1] }, 
                                           new int[] { b1[0] + 1, b1[1] }, new int[] { b2[0] + 1, b2[1] }) };
    } else 
    { return new WallMove[] { new WallMove(a1, b1, a2, b2), // criss cross member
                              new WallMove(new int[] { a1[0], a1[1] - 1 }, new int[] { a2[0], a2[1] - 1 }, 
                                           new int[] { b1[0], b1[1] - 1 }, new int[] { b2[0], b2[1] - 1 }),
                              new WallMove(new int[] { a1[0], a1[1] + 1 }, new int[] { a2[0], a2[1] + 1 }, 
                                           new int[] { b1[0], b1[1] + 1 }, new int[] { b2[0], b2[1] + 1 }) };
    }
  }

  public int compareTo(Object o)
  { if(!(o instanceof WallMove)) return 1;
    WallMove other = (WallMove)o;
    int[] bottomLeft = getBottomLeft();
    int[] otherBottomLeft = other.getBottomLeft();
    if(bottomLeft[0] != otherBottomLeft[0]) return otherBottomLeft[0] - bottomLeft[0];
    else if(bottomLeft[1] != otherBottomLeft[1]) return otherBottomLeft[1] - bottomLeft[1];
    else if(isHorizontal() != other.isHorizontal()) return 1;
    else return 0;
  }

  public int compareTo2(Object o)
  { if(!(o instanceof WallMove)) return 1;
    WallMove other = (WallMove)o;
    int res = 0;
    if(this.a1[0] != other.a1[0]) res = -1;
    if(this.a1[1] != other.a1[1]) res = -1;
    if(this.b1[0] != other.b1[0]) res = -1;
    if(this.b1[1] != other.b1[1]) res = -1;
    if(this.a2[0] != other.a2[0]) res = -1;
    if(this.a2[1] != other.a2[1]) res = -1;
    if(this.b2[0] != other.b2[0]) res = -1;
    if(this.b2[1] != other.b2[1]) res = -1;
   
    return res;
  }
}